package com.linkage.educloud.ah.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mr'Tang on 2018/11/7.
 */

public class TopicChildBean {
    private String id;
    private String name;
    private String img;
    private String stick;  //1---置顶
    private String nick;
    private String publish_time;
    private int comment_num;
    private String content;
    private int zan_num;
    private int is_zan; //1---已赞
    private int read_num;
    private String label;  //有返回则展示标签
    private int permit_comment;  //不为1  不让评论
    private String address; //分享的地址
    private String face;//头像

    //我的帖子列表返回list
    public static List<TopicChildBean> parseFromJson3(JSONArray jsonArray) {
        List<TopicChildBean> list = new ArrayList<>();
        for (int a = 0; a < jsonArray.length(); a++) {
            TopicChildBean topic = new TopicChildBean();
            JSONObject obj = null;
            try {
                obj = jsonArray.getJSONObject(a);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            topic.setContent(obj.optString("content"));
            topic.setId(obj.optString("id"));
            topic.setFace(obj.optString("face"));
            topic.setPublish_time(obj.optString("publish_time"));
            topic.setNick(obj.optString("nick"));
            topic.setName(obj.optString("name"));
            topic.setLabel(obj.optString("topic_name"));
            topic.setComment_num(obj.optInt("comment_num"));
            topic.setZan_num(obj.optInt("zan_num"));
            list.add(topic);
        }
        return list;
    }

    //话题详情评论返回list
    public static List<TopicChildBean> parseFromJson2(JSONArray jsonArray) {
        List<TopicChildBean> list = new ArrayList<>();
        for (int a = 0; a < jsonArray.length(); a++) {
            TopicChildBean topic = new TopicChildBean();
            JSONObject obj = null;
            try {
                obj = jsonArray.getJSONObject(a);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            topic.setContent(obj.optString("content"));
            topic.setFace(obj.optString("face"));
            topic.setId(obj.optString("id"));
            topic.setNick(obj.optString("nick"));
            topic.setPublish_time(obj.optString("publish_time"));
            topic.setZan_num(obj.optInt("zan_num"));
            topic.setIs_zan(obj.optInt("is_zan"));
            list.add(topic);
        }
        return list;
    }

    //话题详情返回对象
    public static TopicChildBean parseFromJson1(JSONObject obj) {
        TopicChildBean topic = new TopicChildBean();
        topic.setComment_num(obj.optInt("comment_num"));
        topic.setContent(obj.optString("content"));
        topic.setId(obj.optString("id"));
        topic.setImg(obj.optString("img"));
        topic.setName(obj.optString("name"));
        topic.setNick(obj.optString("nick"));
        topic.setPublish_time(obj.optString("publish_time"));
        topic.setZan_num(obj.optInt("zan_num"));
        topic.setIs_zan(obj.optInt("is_zan"));
        topic.setRead_num(obj.optInt("read_num"));
        topic.setLabel(obj.optString("label"));
        topic.setPermit_comment(obj.optInt("permit_comment"));
        topic.setAddress(obj.optString("address"));
        return topic;
    }

    //话题列表返回list
    public static List<TopicChildBean> parseFromJson(JSONArray jsonArray) {
        List<TopicChildBean> list = new ArrayList<>();
        for (int a = 0; a < jsonArray.length(); a++) {
            TopicChildBean topic = new TopicChildBean();
            JSONObject obj = null;
            try {
                obj = jsonArray.getJSONObject(a);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            topic.setComment_num(obj.optInt("comment_num"));
            topic.setContent(obj.optString("content"));
            topic.setId(obj.optString("id"));
            topic.setImg(obj.optString("img"));
            topic.setName(obj.optString("name"));
            topic.setNick(obj.optString("nick"));
            topic.setPublish_time(obj.optString("publish_time"));
            topic.setStick(obj.optString("stick"));
            list.add(topic);
        }
        return list;
    }

    public String getFace() {
        return face;
    }

    public void setFace(String face) {
        this.face = face;
    }

    public int getIs_zan() {
        return is_zan;
    }

    public void setIs_zan(int is_zan) {
        this.is_zan = is_zan;
    }

    public int getRead_num() {
        return read_num;
    }

    public void setRead_num(int read_num) {
        this.read_num = read_num;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public int getPermit_comment() {
        return permit_comment;
    }

    public void setPermit_comment(int permit_comment) {
        this.permit_comment = permit_comment;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getZan_num() {
        return zan_num;
    }

    public void setZan_num(int zan_num) {
        this.zan_num = zan_num;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getStick() {
        return stick;
    }

    public void setStick(String stick) {
        this.stick = stick;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public String getPublish_time() {
        return publish_time;
    }

    public void setPublish_time(String publish_time) {
        this.publish_time = publish_time;
    }

    public int getComment_num() {
        return comment_num;
    }

    public void setComment_num(int comment_num) {
        this.comment_num = comment_num;
    }
}

